package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.list.SearchFeignClient;
import com.atguigu.gmall.model.list.SearchParam;
import com.atguigu.gmall.model.vo.GoodsSearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @Author 卡尼奶
 * @Date 2022/5/27 15:55
 * @Version 1.0
 */
@Controller
public class ListController {

    @Autowired
    private SearchFeignClient searchFeignClient;

    @GetMapping("/list.html")
    public String search(SearchParam param, Model model){
        //远程检索商品
        Result<GoodsSearchResultVo> result = searchFeignClient.searchGoods(param);
        if (result.isOk()){
            GoodsSearchResultVo data = result.getData();
            //搜索参数封装
            model.addAttribute("searchParam",data.getSearchParam());

            //品牌的面包屑
            model.addAttribute("trademarkParam",data.getTrademarkParam());

            //URl参数
            model.addAttribute("urlParam",data.getUrlParam());

            //平台属性面包屑
            model.addAttribute("propsParamList",data.getPropsParamList());

            //品牌集合
            model.addAttribute("trademarkList",data.getTrademarkList());

            //平台属性集合
            model.addAttribute("attrsList",data.getAttrsList());

            //排序
            model.addAttribute("orderMap",data.getOrderMap());

            //商品列表
            model.addAttribute("goodsList",data.getGoodsList());

            //当前页
            model.addAttribute("pageNo",data.getPageNo());

            //总页数
            model.addAttribute("totalPages",data.getTotalPages());
        }


        return "list/index";
    }
}
